import { useState, useEffect } from 'react'
import { Tooltip, Image, Button, Space, Divider, Input, message } from 'antd'
import Gg, { stateHook } from "./gg";
import Gongsha from "./gongsha";
import s from "./index.module.less";
import Img1 from "@/assets/img/1.png";
import Img1_2 from "@/assets/img/1-2.png";
import Img1_3 from "@/assets/img/1-3.png";
import Img1_4 from "@/assets/img/1-4.png";
import Img2 from "@/assets/img/2.png";
import Img3 from "@/assets/img/3.png";
import Img4 from "@/assets/img/4.png";
import Img5 from "@/assets/img/5.png";
import Img6 from "@/assets/img/6.png";

function App(): JSX.Element {

  const [config, setConfig] = useState<any>({
    ...stateHook(),
    npcText: `;==============新人接待、礼包=================\r\n微信礼包\\会员站礼包 主城代码 343 335 免费礼包一\\会员站礼包 0 238 0\r\n微信礼包\\微信礼包   主城代码 346 335 免费礼包二\\微信礼包   0 201 0\r\n微信礼包\\技能修复   主城代码 353	322 没事别乱点\\技能修复 0 201 0\r\n新人接待\\二级修改   主城代码 15	14 二级修改 0	208 0\r\n\r\n微信礼包\\会员站礼包 xsjd  9 14 免费礼包一\\会员站礼包 0 238 0\r\n微信礼包\\微信礼包   xsjd 15 20 免费礼包二\\微信礼包   0 201 0\r\n新人接待\\点我出去   xsjd  15	 8 点我出去 0	203 0\r\n新人接待\\点我出去   xsjd  21	14 点我出去 0	203 0\r\n新人接待\\设置密保   xsjd  15	14 设置密保 0	208 0\r\n微信礼包\\无对话		 xsjd	11	9	否则删号\\★禁止角色使用空白字符名字★\\┅┅┅┅┅┅┅┅	0	8       0\r\n新人接待\\二级验证  yz 556	621 二级验证 0	208 0\r\n
;===============================\r\n`,
    EffectImageList: `37WGAME.pak\r\n`,
    mapVal: `[xsjd|Q004 新手接待大厅] safe NoTALLOWUSEITEMS(回城卷|盟重回城石|回城石|比齐传送石|比齐回城石|盟重传送石) SayLevel(65535) NoShop NoDeal NoDrug QUIZ NoPositionMove NoRecall NoDearRecall NoGuildRecall NOMasterRecall NoRandomMove MISSION NOTALLOWUSEMAGIC(瞬息移动)\r\n
[yz|Q004 二级验证] safe NoTALLOWUSEITEMS(回城卷|盟重回城石|回城石|比齐传送石|比齐回城石|盟重传送石) SayLevel(65535) NoShop NoDeal NoDrug QUIZ NoPositionMove NoRecall NoDearRecall NoGuildRecall NOMasterRecall NoRandomMove MISSION NOTALLOWUSEMAGIC(瞬息移动)\r\n`,
    StartPoint: 'xsjd	15	13	0	10	4	0	0	0',
    ESP: '',
    qm: '',
  })

  const getVal = async (type = 3) => {
    if (!config.path2) {
      return message.info('请输入会员站配置文件的路径')
    }

    const c = {
      ...config
    }
    if (type === 1 || type === 3) {
      c.ESP = await window.api.getVal(config.path2, '步骤2', 'qf.txt')
    }
    if (type === 2 || type === 3) {
      c.qm = await window.api.getVal(config.path2, '步骤2', 'qm.txt')
    }
    setConfig(c)

    return c
  }

  useEffect(() => {
    getVal()
  }, [])

  return (
    <>
      <div className={s.box}>
        <Divider>会员站|新手接待</Divider>
        <Gg config={config} setConfig={setConfig} />

        <div>
          <p>
            要复制到Merchant.txt的内容(<span style={{ color: 'red' }}>里面的‘主城代码’自动替换上面输入的主城代码，根据需要自己手动修改</span>):
            <br />
            <Tooltip title={<Image src={Img1} />}>
              <Button size='small' type='primary' onClick={async () => {
                await window.api.huiyuan2(config)
              }}>点击自动复制内容并打开Merchant.txt</Button>
            </Tooltip>
          </p>
          <div className='flex'>
            <Input.TextArea
              spellCheck="false"
              autoSize
              value={config.npcText}
              onChange={(e) => {
                const c = {
                  ...config
                }
                c.npcText = e.target.value
                setConfig(c)
              }}
            />
          </div>
        </div>

        <div>
          <p>
            要复制到EffectImageList的内容:
            <Tooltip title={<Image src={Img2} />}>
              <Button size='small' type='primary' onClick={async () => {
                window.api.copePath(config.EffectImageList)
                window.api.openFile(config, 'EffectImageList.txt')
              }}>点击自动复制内容并打开EffectImageList.txt</Button>
            </Tooltip>
          </p>
          <div className='flex'>
            <Input.TextArea
              spellCheck="false"
              autoSize
              value={config.EffectImageList}
              onChange={(e) => {
                const c = {
                  ...config
                }
                c.EffectImageList = e.target.value
                setConfig(c)
              }}
            />
          </div>
        </div>

        <div>
          <p>
            要复制到qf的Esp内容:
            <Button size='small' type='primary'
              onClick={() => getVal(1)}
            >获取最新内容</Button>

            <Tooltip title={<Image src={Img3} />}>
              <Button size='small' type='primary' style={{ marginLeft: 10 }} onClick={async () => {
                if (!config.ESP) {
                  return message.info('请先点击获取内容')
                }
                window.api.copePath(config.ESP)
                window.api.openFile(config, 'Market_Def', 'QFunction-0.txt')
              }}>点击自动复制内容并打开qf文件</Button>
            </Tooltip>
          </p>
          <div className='flex'>
            <Input.TextArea
              spellCheck="false"
              autoSize
              value={config.ESP}
              onChange={(e) => {
                const c = {
                  ...config
                }
                c.ESP = e.target.value
                setConfig(c)
              }}
            />
          </div>
        </div>

        <div>
          <p>
            要复制到qm的登录初始化内容:
            <Button size='small' type='primary'
              onClick={() => getVal(2)}
            >获取最新内容</Button>

            <Tooltip title={<Image src={Img4} />}>
              <Button size='small' type='primary' style={{ marginLeft: 10 }} onClick={async () => {
                if (!config.qm) {
                  return message.info('请先点击获取内容')
                }
                window.api.copePath(config.qm)
                window.api.openFile(config, 'MapQuest_def', 'QManage.txt')
              }}>点击自动复制内容并打开qm文件</Button>
            </Tooltip>
          </p>
          <div className='flex'>
            <Input.TextArea
              spellCheck="false"
              autoSize
              value={config.qm}
              onChange={(e) => {
                const c = {
                  ...config
                }
                c.qm = e.target.value
                setConfig(c)
              }}
            />
          </div>
        </div>

        <div>
          <p>
            要复制到mapInfo的新手接待大厅地图内容(<span style={{ color: 'red' }}>里面的‘Q004’是默认新手地图，根据需要自己手动修改</span>):
            <br />
            <Tooltip title={<Image src={Img5} />}>
              <Button size='small' type='primary' onClick={async () => {
                window.api.openMapInfo(config)
              }}>点击自动复制内容并打开MapInfo文件</Button>
            </Tooltip>
          </p>
          <div className='flex'>
            <Input.TextArea
              spellCheck="false"
              autoSize
              value={config.mapVal}
              onChange={(e) => {
                const c = {
                  ...config
                }
                c.mapVal = e.target.value
                setConfig(c)
              }}
            />
          </div>
          <br />
          <div>
            <Tooltip title={<Image src={Img6} />}>
              <Button size='small' type='primary' onClick={async () => {
                window.api.copePath(config.StartPoint)
                window.api.openFile(config, 'StartPoint.txt')
              }}>点击自动复制内容并打开StartPoint文件</Button>
            </Tooltip>
            <br />
            <Input.TextArea
              spellCheck="false"
              autoSize
              value={config.StartPoint}
              onChange={(e) => {
                const c = {
                  ...config
                }
                c.StartPoint = e.target.value
                setConfig(c)
              }}
            />
          </div>
        </div>

        <Space>
          <Tooltip title={<Image src={Img1_2} />}>
            <Button size='small' type='primary' onClick={async () => {
              const isTure = await window.api.huiyuan(config)
              if (isTure) {
                message.info('修改成功')
                window.api.openFile(config, 'Market_Def')
              } else {
                message.info('请填写完整')
              }
            }}>复制微礼和新人接待到Market_Def</Button>
          </Tooltip>
          <br />
          <Tooltip title={<Image src={Img1_3} />}>
            <Button size='small' type='primary' onClick={async () => {
              const isTure = await window.api.huiyuan3(config)
              if (isTure) {
                message.info('修改成功')
                window.api.openFile(config, 'QuestDiary')
              } else {
                message.info('请填写完整')
              }
            }}>复制文件放入qu(二级密码等文件)</Button>
          </Tooltip>


          <Tooltip title={<Image src={Img1_4} />}>
            <Button size='small' type='primary' onClick={async () => {
              const isTure = await window.api.huiyuan4(config)
              if (isTure) {
                message.info('修改成功')
              } else {
                message.info('请填写完整')
              }
            }}>复制通区文件到版本文件同级目录</Button>
          </Tooltip>
        </Space>
      </div>

      <Gongsha configF={config} />
    </>
  )
}

export default App
